<?php
//!!!!!!!!!!!!!!!!!!checking svn------------
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	public function _initRequest(){

		$this->_setDefaultAdapter();

		$this->_setAuthAdapter(Zend_Db_Table::getDefaultAdapter());

		$this->_setAcl();

		//var_dump(Zend_Controller_Front::getInstance()->getRequest());

	}

	protected function _setAcl(){
		$acl = new Zend_Acl();
		$acl->addRole(new Zend_Acl_Role('user'));
		$acl->addRole(new Zend_Acl_Role('manager'),'user');
		$acl->addRole(new Zend_Acl_Role('administrator'),'manager');
//
		$acl->addResource('index');
		$acl->addResource('auth');
		$acl->addResource('category');
		$acl->addResource('error');
		$acl->addResource('user');

		$acl->allow('user','index','index');
		//$acl->deny('user','index','edit');//???????????????????????
		$acl->allow('user','auth');
     	$acl->allow('user','error','denied');
		//$acl->allow('user','category');

		$acl->allow('manager',null,array('edit','index'));
		$acl->allow('administrator','index','index');
		
		//$acl->deny('manager','category');
		$acl->allow('administrator','index',null);
		$acl->allow('administrator',null,null);
		Zend_Registry::set('acl', $acl);

	}

	protected function _setDefaultAdapter(){
		$dbAdapter = new Zend_Db_Adapter_Pdo_Mysql(array(
                  'host'     => 'localhost',
                  'username' => 'shop',
                  'password' => 'shop',
                  'dbname'   => 'shop'
                  ));
                  //$dbAdapter = Zend_Db_Table::getDefaultAdapter();

                  //Zend_Registry::set('dbAdapter',$dbAdapter);
                  Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
                  $dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ);

	}

	protected function _setAuthAdapter($dbAdapter){
		if(is_null($dbAdapter))
		{
			if(!is_null(Zend_Db_Table::getDefaultAdapter()))
			{
				$dbAdapter = Zend_Db_Table::getDefaultAdapter();
			}
			else
			{
				return false;
			}
		}
		else
		{
			$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
			//var_dump($authAdapter);

			$authAdapter->setTableName('users')
			->setIdentityColumn('username')
			->setCredentialColumn('password')
			->setCredentialTreatment('SHA1(CONCAT(?,salt))');

			Zend_Registry::set('authAdapter',$authAdapter);
		}


	}
}



